/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package MeshlessShapeFunctions;

        /**
 *
 * @author mark
 */
public class JGaussian implements IKernelFunction{
	
		double rho;
        double exp9 = Math.exp(-9.0);
    public  JGaussian(double rho){
    	this.rho = rho;    	
    }
    public double evaluateNorm(double x, double y) {
        double xx = Math.sqrt(x*x + y*y);

        if( xx > 1.0 ){
            return 0.0;
        }else{
            return (Math.exp(-9 * xx * xx) - exp9)/(1.0 - exp9);
        }
    }

    public double evaluateSque(double x, double y) {
        return evaluateNorm(x, 0)*evaluateNorm(0, y);
    }

    public double evaluatePrimeNormX(double x, double y) {
        double xx = Math.sqrt(x*x + y*y);

        if( xx > 1.0 ){
            return 0.0;
        }else{
            return (Math.exp(-9 * xx * xx) *(-18.0)*xx)/(1.0 - exp9);
        }
    }

    public double evaluatePrimeNormY(double x, double y) {
        System.out.println("swhvbkjahsblsavbfaslkhlasbvksshbjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj");
        throw new UnsupportedOperationException("Not supported yet.");

    }

    public double evaluatePrimeSqueX(double x, double y) {
        return evaluateDerivaty(x)*evaluate(y);
    }

    public double evaluatePrimeSqueY(double x, double y) {
        return evaluate(x)*evaluateDerivaty(y);
    }

    public double evaluate(double x) {
        if( Math.abs(x) > 1.0 ){
            return 0.0;
        }else{
            return (Math.exp(-9 * x * x) - exp9)/(1.0 - exp9);
        }
    }

    public double evaluateDerivaty(double d) {
        if( Math.abs(d) > 1.0 ){
             return 0.0;
         }else{
         	if (d>=0) {
         		return ( -18*d*Math.exp(-9 * d * d) )/(1.0 - exp9)/rho;
 			} else {
 				return ( -18*d*Math.exp(-9 * d * d) )/(1.0 - exp9)/rho;
 			}
         }
     }
    
    public double evaluateSecondDerivaty(double d) {
        if( Math.abs(d) > 1.0 ){
             return 0.0;
         }else{
//         	if (d>=0) {
         		return ( 324*d*d*Math.exp(-9 * d * d) - 18*Math.exp(-9 * d * d) )/(1.0 - exp9)/rho/rho;
// 			} else {
// 				return ( -324*d*d*Math.exp(-9 * d * d) + 18*Math.exp(-9 * d * d) )/(1.0 - exp9);
// 			}
         }
     }

    public static void main(String[] args){
        double a =-1.5,b=1.5,
        h=0.01;
        double x = a;

        IKernelFunction f  = new JGaussian(1);

        while(x<b+h){
        	double r = 0.0;
        	if(Math.abs(x)<1){r=Math.exp(1.0/ (x*x-1.0)) * (-2*x/(x*x-1)/(x*x-1));}
//            System.out.println(x+"\t"+f.evaluateDerivaty(x));
        	System.out.println(x+"\t"+r);
            x+=h;
        }
    }

}
